package com.huluobo.a2203parkdemo.signin

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.LoginBean
import com.huluobo.base.bean.SignBean
import com.huluobo.base.db.UserDao
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2024/7/26.
 */
@HiltViewModel
class SignInViewModel @Inject constructor(
    val apiService: ApiService,
    val userDao: UserDao
) : BaseViewModel() {
    val signInSuccess by lazy { MutableLiveData<String>() }
    val signOutSuccess by lazy { MutableLiveData<String>() }
    val getUserComplete by lazy { MutableLiveData<LoginBean>() }
    fun signIn(body: RequestBody) {
        executeNetRequest(
            { apiService.signIn(body) },
            signInSuccess::postValue
        )
    }

    fun signOut(body: RequestBody) {
        executeNetRequest(
            { apiService.signOut(body) },
            signOutSuccess::postValue
        )
    }

    fun getUser(username: String) {
        executeDb(
            { userDao.queryUserInfo(username) },
            getUserComplete::postValue
        )
    }

    val getAllSignSuccess by lazy { MutableLiveData<String>() }

    fun getAllSign(body: RequestBody) {
        executeNetRequest(
            { apiService.getAllSign(body) },
            getAllSignSuccess::postValue
        )
    }
}